<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册 - 创建新账户</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#36CFC9',
                        neutral: '#F5F7FA',
                        dark: '#1D2129',
                        success: '#52C41A',
                        danger: '#FF4D4F',
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .form-input-focus {
                @apply focus:border-primary focus:ring-2 focus:ring-primary/20 focus:outline-none;
            }
            .form-input-error {
                @apply border-danger focus:border-danger focus:ring-2 focus:ring-danger/20;
            }
            .transition-custom {
                transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            }
        }
    </style>
</head>
<body class="font-inter bg-neutral min-h-screen flex flex-col">
    <!-- 导航栏 -->
    <header class="bg-white shadow-sm">
        <div class="container mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center h-16">
                <!-- 网站Logo -->
                <div class="flex items-center">
                    <a href="index.html" class="flex items-center space-x-2">
                        <span class="text-primary text-2xl"><i class="fa fa-connectdevelop"></i></span>
                        <span class="font-bold text-xl text-dark">石神的网页</span>
                    </a>
                </div>
                
                <!-- 空区域，保持布局一致 -->
                <div></div>
                
                <!-- 返回首页按钮 -->
                <div class="flex items-center">
                    <a href="index.html" class="inline-flex items-center px-4 py-2 text-dark hover:text-primary transition-custom font-medium">
                        <i class="fa fa-home mr-2"></i>
                        首页
                    </a>
                </div>
            </div>
        </div>
    </header>

    <!-- 主内容区 -->
    <main class="flex-grow flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
        <div class="w-full max-w-md">
            <div class="bg-white rounded-2xl shadow-md overflow-hidden">
                <div class="p-6 sm:p-8">
                    <div class="text-center mb-8">
                        <h2 class="text-2xl font-bold text-dark mb-2">创建新账户</h2>
                        <p class="text-gray-600">填写以下信息注册成为我们的用户</p>
                    </div>
                    
                    <form class="space-y-6" id="registerForm">
                        <!-- 用户名 -->
                        <div>
                            <label for="username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fa fa-user text-gray-400"></i>
                                </div>
                                <input type="text" id="username" name="username" 
                                    class="block w-full pl-10 pr-3 py-3 border border-gray-300 rounded-lg form-input-focus transition-custom"
                                    placeholder="请设置用户名" required>
                                <div class="hidden absolute inset-y-0 right-0 pr-3 flex items-center text-success" id="usernameValid">
                                    <i class="fa fa-check-circle"></i>
                                </div>
                                <div class="hidden absolute inset-y-0 right-0 pr-3 flex items-center text-danger" id="usernameInvalid">
                                    <i class="fa fa-exclamation-circle"></i>
                                </div>
                            </div>
                            <p class="mt-1 text-xs text-gray-500 hidden" id="usernameHelper">用户名长度应为4-20个字符</p>
                            <p class="mt-1 text-xs text-danger hidden" id="usernameError">用户名已被占用或不符合要求</p>
                        </div>
                        
                        <!-- 邮箱 -->
                        <div>
                            <label for="email" class="block text-sm font-medium text-gray-700 mb-1">邮箱</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fa fa-envelope text-gray-400"></i>
                                </div>
                                <input type="email" id="email" name="email" 
                                    class="block w-full pl-10 pr-3 py-3 border border-gray-300 rounded-lg form-input-focus transition-custom"
                                    placeholder="请输入您的邮箱" required>
                                <div class="hidden absolute inset-y-0 right-0 pr-3 flex items-center text-success" id="emailValid">
                                    <i class="fa fa-check-circle"></i>
                                </div>
                                <div class="hidden absolute inset-y-0 right-0 pr-3 flex items-center text-danger" id="emailInvalid">
                                    <i class="fa fa-exclamation-circle"></i>
                                </div>
                            </div>
                            <p class="mt-1 text-xs text-danger hidden" id="emailError">请输入有效的邮箱地址</p>
                        </div>
                        
                        <!-- 密码 -->
                        <div>
                            <label for="password" class="block text-sm font-medium text-gray-700 mb-1">密码</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fa fa-lock text-gray-400"></i>
                                </div>
                                <input type="password" id="password" name="password" 
                                    class="block w-full pl-10 pr-10 py-3 border border-gray-300 rounded-lg form-input-focus transition-custom"
                                    placeholder="请设置密码" required>
                                <button type="button" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 transition-custom" id="togglePassword">
                                    <i class="fa fa-eye-slash"></i>
                                </button>
                            </div>
                            <div class="mt-2 space-y-1">
                                <div class="flex items-center text-xs">
                                    <i class="fa fa-circle text-gray-300 mr-2" id="passwordLengthIcon"></i>
                                    <span class="text-gray-500" id="passwordLengthText">至少8个字符</span>
                                </div>
                                <div class="flex items-center text-xs">
                                    <i class="fa fa-circle text-gray-300 mr-2" id="passwordMixedIcon"></i>
                                    <span class="text-gray-500" id="passwordMixedText">包含字母和数字</span>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 确认密码 -->
                        <div>
                            <label for="confirmPassword" class="block text-sm font-medium text-gray-700 mb-1">确认密码</label>
                            <div class="relative">
                                <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                    <i class="fa fa-lock text-gray-400"></i>
                                </div>
                                <input type="password" id="confirmPassword" name="confirmPassword" 
                                    class="block w-full pl-10 pr-10 py-3 border border-gray-300 rounded-lg form-input-focus transition-custom"
                                    placeholder="请再次输入密码" required>
                                <button type="button" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 transition-custom" id="toggleConfirmPassword">
                                    <i class="fa fa-eye-slash"></i>
                                </button>
                            </div>
                            <p class="mt-1 text-xs text-danger hidden" id="passwordMismatch">两次输入的密码不一致</p>
                        </div>
                        
                        <!-- 同意条款 -->
                        <div class="flex items-start">
                            <div class="flex items-center h-5">
                                <input id="terms" name="terms" type="checkbox" 
                                    class="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary transition-custom" required>
                            </div>
                            <div class="ml-3 text-sm">
                                <label for="terms" class="text-gray-600">
                                    我同意
                                    <a href="#" class="text-primary hover:text-primary/80 transition-custom">服务条款</a>
                                    和
                                    <a href="#" class="text-primary hover:text-primary/80 transition-custom">隐私政策</a>
                                </label>
                            </div>
                        </div>
                        
                        <!-- 注册按钮 -->
                        <div>
                            <button type="submit" 
                                class="w-full flex justify-center items-center px-4 py-3 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-primary hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary transition-custom">
                                注册
                                <i class="fa fa-user-plus ml-2"></i>
                            </button>
                        </div>
                    </form>
                    
                    <!-- 登录链接 -->
                    <div class="mt-6 text-center">
                        <p class="text-gray-600">
                            已有账号？ 
                            <a href="login.html" class="font-medium text-primary hover:text-primary/80 transition-custom">
                                立即登录
                            </a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- 页脚 -->
    <footer class="bg-white border-t border-gray-200 py-6">
        <div class="container mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center text-sm text-gray-500">
                <p>&copy; 2023 Connect. 保留所有权利。</p>
            </div>
        </div>
    </footer>

    <script>
        // 密码显示/隐藏切换
        const togglePassword = document.getElementById('togglePassword');
        const passwordInput = document.getElementById('password');
        const toggleConfirmPassword = document.getElementById('toggleConfirmPassword');
        const confirmPasswordInput = document.getElementById('confirmPassword');
        
        togglePassword.addEventListener('click', function() {
            togglePasswordVisibility(passwordInput, this);
        });
        
        toggleConfirmPassword.addEventListener('click', function() {
            togglePasswordVisibility(confirmPasswordInput, this);
        });
        
        function togglePasswordVisibility(input, button) {
            // 切换密码可见性
            const type = input.getAttribute('type') === 'password' ? 'text' : 'password';
            input.setAttribute('type', type);
            
            // 切换图标
            button.querySelector('i').classList.toggle('fa-eye');
            button.querySelector('i').classList.toggle('fa-eye-slash');
        }
        
        // 用户名验证
        const usernameInput = document.getElementById('username');
        const usernameValid = document.getElementById('usernameValid');
        const usernameInvalid = document.getElementById('usernameInvalid');
        const usernameHelper = document.getElementById('usernameHelper');
        const usernameError = document.getElementById('usernameError');
        
        usernameInput.addEventListener('input', function() {
            const value = this.value.trim();
            usernameHelper.classList.remove('hidden');
            
            if (value.length >= 4 && value.length <= 20) {
                // 这里可以添加更复杂的用户名验证逻辑
                usernameValid.classList.remove('hidden');
                usernameInvalid.classList.add('hidden');
                usernameError.classList.add('hidden');
                this.classList.remove('form-input-error');
                return true;
            } else {
                usernameValid.classList.add('hidden');
                usernameInvalid.classList.remove('hidden');
                usernameError.classList.remove('hidden');
                usernameError.textContent = '用户名长度应为4-20个字符';
                this.classList.add('form-input-error');
                return false;
            }
        });
        
        // 邮箱验证
        const emailInput = document.getElementById('email');
        const emailValid = document.getElementById('emailValid');
        const emailInvalid = document.getElementById('emailInvalid');
        const emailError = document.getElementById('emailError');
        
        emailInput.addEventListener('input', function() {
            const value = this.value.trim();
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            
            if (emailRegex.test(value)) {
                emailValid.classList.remove('hidden');
                emailInvalid.classList.add('hidden');
                emailError.classList.add('hidden');
                this.classList.remove('form-input-error');
                return true;
            } else {
                emailValid.classList.add('hidden');
                emailInvalid.classList.remove('hidden');
                emailError.classList.remove('hidden');
                this.classList.add('form-input-error');
                return false;
            }
        });
        
        // 密码强度验证
        const passwordLengthIcon = document.getElementById('passwordLengthIcon');
        const passwordLengthText = document.getElementById('passwordLengthText');
        const passwordMixedIcon = document.getElementById('passwordMixedIcon');
        const passwordMixedText = document.getElementById('passwordMixedText');
        
        passwordInput.addEventListener('input', validatePassword);
        confirmPasswordInput.addEventListener('input', validatePasswordMatch);
        
        function validatePassword() {
            const password = this.value;
            let lengthValid = false;
            let mixedValid = false;
            
            // 长度验证
            if (password.length >= 8) {
                lengthValid = true;
                passwordLengthIcon.classList.remove('text-gray-300');
                passwordLengthIcon.classList.add('text-success');
                passwordLengthText.classList.remove('text-gray-500');
                passwordLengthText.classList.add('text-success');
            } else {
                passwordLengthIcon.classList.remove('text-success');
                passwordLengthIcon.classList.add('text-gray-300');
                passwordLengthText.classList.remove('text-success');
                passwordLengthText.classList.add('text-gray-500');
            }
            
            // 字母和数字混合验证
            const hasLetters = /[a-zA-Z]/.test(password);
            const hasNumbers = /\d/.test(password);
            
            if (hasLetters && hasNumbers) {
                mixedValid = true;
                passwordMixedIcon.classList.remove('text-gray-300');
                passwordMixedIcon.classList.add('text-success');
                passwordMixedText.classList.remove('text-gray-500');
                passwordMixedText.classList.add('text-success');
            } else {
                passwordMixedIcon.classList.remove('text-success');
                passwordMixedIcon.classList.add('text-gray-300');
                passwordMixedText.classList.remove('text-success');
                passwordMixedText.classList.add('text-gray-500');
            }
            
            return lengthValid && mixedValid;
        }
        
        // 密码匹配验证
        const passwordMismatch = document.getElementById('passwordMismatch');
        
        function validatePasswordMatch() {
            const password = passwordInput.value;
            const confirmPassword = this.value;
            
            if (password !== confirmPassword) {
                passwordMismatch.classList.remove('hidden');
                this.classList.add('form-input-error');
                return false;
            } else {
                passwordMismatch.classList.add('hidden');
                this.classList.remove('form-input-error');
                return true;
            }
        }
        
        // 表单提交处理
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 验证所有字段
            const isUsernameValid = usernameInput.dispatchEvent(new Event('input'));
            const isEmailValid = emailInput.dispatchEvent(new Event('input'));
            const isPasswordValid = validatePassword.call(passwordInput);
            const isPasswordMatch = validatePasswordMatch.call(confirmPasswordInput);
            const termsAccepted = document.getElementById('terms').checked;
            
            // 检查所有验证是否通过
            if (isUsernameValid && isEmailValid && isPasswordValid && isPasswordMatch && termsAccepted) {
                // 在实际应用中，这里会有AJAX请求到服务器创建账户
                alert('注册成功！请登录您的账户');
                window.location.href = 'login.html';
            } else {
                // 显示错误提示
                if (!termsAccepted) {
                    alert('请同意服务条款和隐私政策');
                } else {
                    alert('请检查并修正表单中的错误');
                }
            }
        });
    </script>
</body>
</html>
